package Controller;

import Pojo.Student;
import Service.ServiceImpl.StudentServiceImpl;
import Service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @auther wsy
 * @auther MI
 * @create Servlet_Jdbc_Maven.${PACKAGE_NAME}
 * @create 19:36
 * @create 2021/7/5 星期一
 */

@WebServlet("/login")
public class FindUserByName extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        StudentService studentService = new StudentServiceImpl();
        Student s = new Student();
        s = studentService.findUserByName(username);
        if(username.equals(s.getName())&&password.equals(s.getPassword())){
            request.getRequestDispatcher("/findAll").forward(request,response);

        }else{
            request.getRequestDispatcher("/admin/login.jsp").forward(request,response);
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
